package com.sskj.gocoin.p.activity;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.sskj.gocoin.MyAppLication;
import com.sskj.gocoin.common.Constants;
import com.sskj.gocoin.m.HttpConfig;
import com.sskj.gocoin.m.bean.HttpData;
import com.sskj.gocoin.m.bean.ImgHighBean;
import com.sskj.gocoin.m.http.JsonCallBack;
import com.sskj.gocoin.p.base.BasePresenter;
import com.sskj.gocoin.utils.SPUtils;
import com.sskj.gocoin.utils.ToastUtil;
import com.sskj.gocoin.v.activity.VerifyGuideActivity;

import java.io.File;
import java.util.HashMap;


public class VerifyGuidePresenter extends BasePresenter<VerifyGuideActivity> {
    public void submitVerify(File file, int position) {
        OkGo.<HttpData<ImgHighBean>>post(HttpConfig.BASE_URL + HttpConfig.HIGH_VERIFY_IMG)
                .isMultipart(false)
                .params("file_pic", file)
                .execute(new JsonCallBack<HttpData<ImgHighBean>>(this) {
                    @Override
                    public void _onSuccess(Response<HttpData<ImgHighBean>> response) {
                        HttpData body = response.body();
                        if (body.getCode() == 200) {
                            ToastUtil.showShort(body.msg);
                            mView.putList((ImgHighBean) body.getData(), position);
                        } else {
                            mView.uploadFail(position);
                            ToastUtil.showShort(body.msg);
                        }
                    }
                });
    }

    public void submitVerifyEnd(File img1,File img2,File img3) {
        OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.HIGH_VERIFY)
                .params("front_img", img1)  // 正面
                .params("back_img", img2)//身份证背面
                .params("handheld_img", img3)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void _onSuccess(Response<HttpData> response) {
                        HttpData body = response.body();
                        if (body.getCode() == 200) {
                            mView.onSubmitVerifyResponseSuccess();
                            SPUtils.put(MyAppLication.getApplication(), Constants.SP_REALNAME_STATUS, 2);
                        } else {
//                            mView.onSubmitVerifyResponseSuccess();
                            ToastUtil.showShort(body.msg);
                        }
                    }
                });
    }
}
